/*
 * Project: yygh-parent
 *
 * File Created at 2023/7/20
 *
 * 自定义时间格式代替DATE标签：2023-07-20 18:02:18:02
 */
package com.atguigu.yygh.order.controller;


import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.order.service.HospitalService1;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.web.bind.annotation.*;

import java.util.stream.Stream;

/**
 * @author 用户名
 * @Type HospitalController.java
 * @Desc
 * @date 2023/7/20 18:02
 */
@Api("医院管理接口")
@RestController
//@CrossOrigin
@RequestMapping("/admin/hosp/hospital")
@Slf4j
public class HospitalController {
    @Autowired
    HospitalService1 hospitalService;


    @ApiOperation(value = "获取分页列表")
    @GetMapping("list/{page}/{limit}")
    public Result index(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,

            @ApiParam(name = "hospitalQueryVo", value = "查询对象", required = false)
                    HospitalQueryVo hospitalQueryVo) {
        System.out.println("aaaaaaaaaaaaaaaaaaaa-------------------");
//        if(hospitalQueryVo==null){
//            return Result.fail();
//        }

       Page<Hospital> hospitalPage =hospitalService.selectPage(page,limit,hospitalQueryVo);


        Stream<Hospital> hospitalStream = hospitalPage.get();
        if(hospitalPage!=null){
            hospitalStream.forEach((item)->{
                //到dict里面得到对应的医院等级,为了唯一要得到parentId为10000
                Integer parentId=10000;


                //得到通过码对应的地址
                String detailAddress = hospitalService.getDetailAddress(Integer.parseInt(item.getProvinceCode()), Integer.parseInt(item.getCityCode()),Integer.parseInt(item.getDistrictCode()));
                item.setAddress(detailAddress+item.getAddress());
//            dictService.getAddress
            });
        }

        return Result.ok(hospitalPage);
    }

//    @ApiParam(name = "page", value = "当前页码", required = true)
//    @PathVariable Integer page,
//
//    @ApiParam(name = "limit", value = "每页记录数", required = true)
//    @PathVariable Integer limit,

//    @ApiParam(name = "hospitalQueryVo", value = "查询对象", required = false)
    //
    @ApiOperation(value = "设置上线/未上线状态")
    @GetMapping("updateStatus/{id}/{status}")
    public Result updateStatus(
            @ApiParam(name = "id", value = "id", required = true)   @PathVariable String id,
            @ApiParam(name = "status", value = "状态", required = true) @PathVariable Integer status) {
                hospitalService.updateStatusById(id,status);
            return Result.ok();
    }

    @ApiOperation(value = "指定的医院的详情信息")
    @GetMapping("show/{id}")
    public Result show(
            @ApiParam(name = "id", value = "id", required = true)   @PathVariable String id) {
       Hospital hospital=hospitalService.selectHospitalById(id);
        return Result.ok(hospital);
    }






}


/**
 * Revision history
 * -------------------------------------------------------------------------
 * <p>
 * Date Author Note
 * -------------------------------------------------------------------------
 * 2023/7/20 用户名 create
 */ 
